﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace IronSuit.DataMap
{
    [Serializable]
    public class DataEntity 
    {
        internal Dictionary<string, Object> FieldValueDic = new Dictionary<string, object>();
        protected  internal int GetFieldValue(string FieldName, int  DefaultValue)
        {
            if (FieldValueDic.ContainsKey(FieldName))
            {
                    return (int)(FieldValueDic[FieldName]);
            }
            else
                return DefaultValue;
        }
        protected internal string GetFieldValue(string FieldName, string DefaultValue)
        {
            if (FieldValueDic.ContainsKey(FieldName))
                return FieldValueDic[FieldName].ToString();
            else
                return DefaultValue;
        }
        protected internal DateTime GetFieldValue(string FieldName, DateTime DefaultValue)
        {
            if (FieldValueDic.ContainsKey(FieldName))
                return (DateTime)(FieldValueDic[FieldName]);
            else
                return DefaultValue;
        }
        protected internal void SetFieldValue(string FieldName, object Value)
        {
            FieldValueDic[FieldName] = Value;
        }
		protected virtual internal DataHandler GetDataHandler()
		{
			throw new NotImplementedException();
		}
		/// <summary>
		/// 清空所有字段
		/// </summary>
		public void Clear()
		{
			FieldValueDic.Clear();
		}
		/// <summary>
		/// 替换，把数据获取过来
		/// </summary>
		/// <param name="DE"></param>
		public void Displace(DataEntity DE)
		{
			this.FieldValueDic = DE.FieldValueDic;
		}
		public List<DataEntity> QueryEntityList(string dbStr)
		{
			using (DBFactory dbf = new DBFactory(dbStr))
			{
				return dbf.QueryList(this);
			}
		}
		public bool  Query(string dbStr)
		{
			using (DBFactory dbf = new DBFactory(dbStr))
			{
				return dbf.Query(this);
			}
		}
	}
	
}
